//The Blue Tails transformation

addHook("PlayerThink", function(player)
	if player.mo and player.mo.valid
		if player.bluedelay == nil
			player.bluedelay = 45
		end
		if skins[player.mo.skin].hudname == "TAILS"
		or skins[player.mo.skin].hudname == "Tails"
		or skins[player.mo.skin].hudname == "tails"
		or player.mo.skin == "recenttails"
			player.tailstintblue = true
		else
			player.tailstintblue = false
		end
		if player.bluedelay > 0
			player.bluedelay = $-1
		end
		if player.bluedelay > 60
			player.mo.colorized = true
		elseif player.bluedelay == 59
			player.mo.colorized = false
		end
		if not player.powers[pw_super]
		and player.tailstintblue == true
			if player.isblue != true
				player.mo.color = player.skincolor
			elseif player.isblue == true
				player.mo.color = SKINCOLOR_SAPPHIRE
			end
		end
		if player.cmd.buttons & BT_TOSSFLAG
		and player.tailstintblue == true
		and player.isblue != true
		and player.bluedelay == 0
			P_FlashPal(player, PAL_WHITE, 10)
			S_StartSound(player.mo, sfx_mixup, player)
			player.isblue = true
			player.bluedelay = 70
		elseif player.cmd.buttons & BT_TOSSFLAG
		and player.tailstintblue == true
		and player.isblue == true
		and player.bluedelay == 0
			if player.mo.flags & MF_NOGRAVITY
				if player.tailsflyrun > 0
					if not P_IsObjectOnGround(player.mo)
					and not (player.pflags & PF_JUMPED)
						P_DoJump(player, true)
						player.pflags = $ & ~PF_JUMPED
						player.mo.state = S_PLAY_SPRING
					end
					player.mo.flags = $ & ~MF_NOGRAVITY
					player.tailsflyrun = 0
				end
			end
			player.followmobj.flags2 = $ & ~MF2_DONTDRAW
			P_FlashPal(player, PAL_NUKE, 10)
			S_StartSound(player.mo, sfx_mixup, player)
			player.isblue = false
			player.bluedelay = 70
		end
	end
end)